package xyz.scootaloo.mono.data.entity.auth

import org.ktorm.database.Database
import org.ktorm.entity.Entity
import org.ktorm.entity.sequenceOf
import org.ktorm.global.findAll
import org.ktorm.schema.Table
import org.ktorm.schema.datetime
import org.ktorm.schema.int
import org.ktorm.schema.varchar
import java.time.LocalDateTime

/**
 * @author flutterdash@qq.com
 * @since 2021/9/9 16:13
 */
interface AuthMenu : Entity<AuthMenu> {
    companion object : Entity.Factory<AuthMenu>()

    var id: Int
    var path: String
    var name: String
    var parent: Int
    var status: Int
    var icon: String
    var created: LocalDateTime
    var updated: LocalDateTime
}

object AuthMenus : Table<AuthMenu>("auth_menu") {
    private val id = int("id").primaryKey().bindTo { it.id }
    private val path = varchar("path").bindTo { it.path }
    private val name = varchar("name").bindTo { it.name }
    private val parent = int("parent").bindTo { it.parent }
    private val status = int("status").bindTo { it.status }
    private val icon = varchar("icon").bindTo { it.icon }
    private val created = datetime("created").bindTo { it.created }
    private val updated = datetime("updated").bindTo { it.updated }

    fun list(): List<AuthMenu> = findAll()
}

val Database.authMenus get() =  this.sequenceOf(AuthMenus)
